#ifndef AUDIO_H
#define AUDIO_H

#include <QObject>
#include <QAudioFormat>
#include <QScopedPointer>

class QAudioInput;
class QAudioOutput;
class QIODevice;
class QTcpSocket;

class AudioService : public QObject
{
    Q_OBJECT

public:
    explicit AudioService(QObject *parent = nullptr);
    ~AudioService();

    // 音频格式设置
    void setAudioFormat(const QAudioFormat &format);
    QAudioFormat audioFormat() const;
    
    // 启用/禁用音频传输
    void setEnabled(bool enabled);
    bool isEnabled() const;
    
    // 设置协议处理器
    void setProtocol(QObject *protocol);

public slots:
    // 开始/停止本地音频捕获
    void startCapture();
    void stopCapture();
    
    // 播放远程音频数据
    void playAudioData(const QByteArray &data);

private slots:
    // 处理音频数据
    void onAudioDataReady();
    void onAudioStateChanged();
    
    // 网络数据处理
    void onNetworkDataReceived();

private:
    void initializeAudio();
    void cleanupAudio();
    
    QAudioFormat format;
    QAudioInput *audioInput;
    QAudioOutput *audioOutput;
    QIODevice *inputDevice;
    QIODevice *outputDevice;
    QTcpSocket *networkSocket;
    
    QObject *protocol;
    bool enabled;
    bool capturing;
};

#endif // AUDIO_H